
package Controller;

import com.mysql.jdbc.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Gastos {
    public static Statement st; 
    public static ResultSet rs, rs1;
    public static int id;
    
    public static ResultSet selectGastos(){
     st = Controller.Conexion.conectar();
        try {
            rs = st.executeQuery("SELECT dia,total_gastada,descripcion from gastos");
        } catch (SQLException ex) {
            Logger.getLogger(Ventas.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return rs;
    
    }
    public static void cargaBd(String fecha, float total, String desc) throws SQLException{
       
            st = Controller.Conexion.conectar();
            rs= st.executeQuery("SELECT id FROM gastos");
            if (rs != null && rs.next()) {
             
                rs1 = st.executeQuery("SELECT max(id) FROM gastos"/*
                         * "SELECT id FROM ventas ORDER BY 'id' DESC LIMIT 1"
                         */);
                 
                while (rs1.next()) {
                    id = ((Integer) rs1.getObject(1)) + 1;
                   
                }
                    Statement st2 = (Statement) Controller.Conexion.conectar();
                    st2.executeUpdate("INSERT INTO gastos (id, descripcion, dia, total_gastada) VALUES (" + id + ",'" + desc + "','" + fecha + "',"+total+")");
                   

            } else {
                    Statement st1 = (Statement) Controller.Conexion.conectar();
                    st1.executeUpdate("INSERT INTO gastos (id, descripcion, dia,total_gastada) VALUES (" + 1 + ",'" + desc + "','" + fecha + "',"+total+")");
                }
            }
    
      public static void borrarDatos(){
        Statement st1 = (Statement) Controller.Conexion.conectar();
        try {
            st1.executeQuery("TRUNCATE gastos");
             
        } catch (SQLException ex) {
            Logger.getLogger(Caja.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    
    }
    
    }

